package leetcode.sword;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Solution60 {

    public static void main(String[] args) {

//        double[] res = new Solution60().dicesProbability(11);
////        for (int i = 0; i < res.length; i++) {
////            System.out.println(res[i]);
////        }
        System.out.println((3<4?3:4)+1);
        HashMap<Integer, Integer> hashMap = new HashMap<>();
        hashMap.put(0,hashMap.getOrDefault(0,1));
        Iterator<Map.Entry<Integer,Integer>> iterator = hashMap.entrySet().iterator();
//        while (iterator.hasNext()){
//            Map.Entry<Integer,Integer> entry =  iterator.next();
//            if(entry.getValue()==1) return entry.getKey();
//        }
    }

    public double[] dicesProbability(int n) {
        //回溯
        double total = Math.pow(6,n);
        double[] res = new double[5*n+1]; //从n到6n
        backTracking(res,0,0,n);
        for (int j = 0; j<res.length; j++) {
            if(j<=(res.length-1)/2){//把右边除total
                res[j] /= total;
            }else{//把右边复制到左边
                res[j] = res[res.length-1-j];
            }
        }
        return res;
    }

    public void backTracking(double[] res, int depth, int sum, int base){
        if(sum>7*base/2) return;
        if(depth==base){
            res[sum-base] ++;
            return;
        }
        for (int i = 1; i <= 6; i++) {
            sum += i;
            backTracking(res,depth+1,sum,base);
            sum -= i;
        }
    }
}
